<?xml version="1.0"?>
<!--
linechart.xsl
$Revision: 4 $
Outputs a line chart.

Created by: Virgil Dupras
Created on: 2004/09/09

Last modified by:$Author: hardcoded.software $
Last modified on:$Date: 2006-08-26 14:05:46 +0000 (Sat, 26 Aug 2006) $

Copyright (C) 2004-2006 Virgil Dupras (http://www.hardcoded.net)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2000/svg" exclude-result-prefixes="#default">
                
<xsl:output 
	method="xml"
	doctype-public="-//W3C//DTD SVG 1.0//EN"
	doctype-system="http://www.w3.org/TR/SVG/DTD/svg10.dtd"
	indent="yes"/>
	
<xsl:template name="draw_line"> <!-- This is called when the man script processes a 'serie' -->
	<g style="stroke:{color};stroke-width:3;fill:none;">
		<xsl:variable name="xmax" select="/hsgraph/xaxis/max"/>
		<xsl:variable name="ymax" select="/hsgraph/yaxis/max"/>
	    <xsl:variable name="ymin" select="sum(/hsgraph/yaxis/min)"/> <!-- A hack to make the script work even if there is no min element -->
	    <xsl:variable name="ydelta" select="$ymax - $ymin"/>
		<xsl:variable name="xwidth" select="500 div ($xmax - 1)"/>
		<xsl:variable name="ywidth" select="300 div $ydelta"/>
		<xsl:variable name="scount" select="count(../*)"/>
		<xsl:variable name="xunit" select="($xwidth div 2) div $scount"/>
		<xsl:element name="path">
			<xsl:attribute name="d">
				<xsl:for-each select="point">
					<xsl:variable name="xpos" select="(@x * $xwidth)"/>
					<xsl:variable name="myheight" select="(@y - $ymin) * $ywidth"/>
					<xsl:variable name="ypos" select="300 - $myheight"/>
					<xsl:if test="position() = 1">
						<xsl:text>M </xsl:text>
					</xsl:if>
					<xsl:if test="position() > 1">
						<xsl:text>L </xsl:text>
					</xsl:if>
					<xsl:value-of select="$xpos"/><xsl:text> </xsl:text><xsl:value-of select="$ypos"/><xsl:text> </xsl:text>
				</xsl:for-each>	
			</xsl:attribute>
		</xsl:element>
		<xsl:if test="../@showvalues">
			<xsl:for-each select="point">
				<xsl:variable name="xpos" select="(@x * $xwidth)"/>
				<xsl:variable name="myheight" select="(@y - $ymin) * $ywidth"/>
				<xsl:variable name="ypos" select="300 - $myheight"/>
				<text class="values" x="{round($xpos)}" y="{round($ypos - 2)}">
					<xsl:if test="../@valuecolor or position() = 1 or position() = last()">
						<xsl:attribute name="style">
							<xsl:if test="../@valuecolor">
								<xsl:text>fill:</xsl:text><xsl:value-of select="../@valuecolor"/><xsl:text>;</xsl:text>
							</xsl:if>
							<xsl:if test="position() = 1">
								<xsl:text>text-anchor:start;</xsl:text>
							</xsl:if>
							<xsl:if test="position() = last()">
								<xsl:text>text-anchor:end;</xsl:text>
							</xsl:if>
						</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="@y"/>
				</text>
			</xsl:for-each>
		</xsl:if>
	</g>
</xsl:template>

</xsl:stylesheet>